<!-- /components/custom-section/custom-section.vue -->
<!-- ctrl + k     ctrl + 0   一键折叠所有代码 -->
<script setup lang="ts">
  // 提供外部数据未传入时的默认值
  const sectionProps = withDefaults(
    // @Props 接收外部数据
    defineProps<{
      // 控制标题
      title?: string
      // 控制箭头
      showArrow?: boolean
      // 自定义样式
      customStyle?: object
    }>(),
    {
      title: '',
      showArrow: false,
      // @ts-ignore
      customStyle: {},
    }
  )
</script>

<template>
  <view class="custom-section" :style="{ ...sectionProps.customStyle }">
    <view class="custom-section-header">
      <view class="section-header-title">{{ sectionProps.title }}</view>
      <view class="section-header-right">
        <!-- 接收外部的有名结构  template #插槽名 -->
        <slot name="right" />
        <uni-icons v-if="sectionProps.showArrow" color="#c3c3c5" size="16" type="forward" />
      </view>
    </view>
    <!-- 接收外部的默认结构 -->
    <slot />
  </view>
</template>

<style lang="scss">
  .custom-section {
    padding: 40rpx 30rpx 30rpx;
    margin-bottom: 20rpx;
    background-color: #fff;
    border-radius: 20rpx;
  }

  .custom-section-header {
    display: flex;
    justify-content: space-between;
    line-height: 1;
    margin-bottom: 20rpx;
  }

  .section-header-title {
    font-size: 32rpx;
    color: #333;
  }

  .section-header-right {
    display: flex;
    align-items: center;
    font-size: 26rpx;
    color: #c3c3c5;
  }
</style>
